package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.sc.nft.enums.DaoEcologyMarketValueRecordsStatusEnum;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.DaoEcologyMarketValueRecords;
import com.sc.nft.mapper.DaoEcologyMarketValueRecordsMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

/**
 * DAO-市值管理记录(sc_dao_ecology_market_value_records)数据DAO
 *
 * @author Sun
 * @since 2024-01-09 16:35:48
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class DaoEcologyMarketValueRecordsDao extends ServiceImpl<DaoEcologyMarketValueRecordsMapper, DaoEcologyMarketValueRecords> {

    public DaoEcologyMarketValueRecords getLastOneByDaoIdAndStatus(Long daoId, DaoEcologyMarketValueRecordsStatusEnum status) {
        LambdaQueryWrapper<DaoEcologyMarketValueRecords> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DaoEcologyMarketValueRecords::getDaoId, daoId);
        wrapper.eq(DaoEcologyMarketValueRecords::getStatus, status);
        wrapper.orderByDesc(DaoEcologyMarketValueRecords::getId);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }

    public boolean updateStatusById(Long id, DaoEcologyMarketValueRecordsStatusEnum status) {
        LambdaUpdateWrapper<DaoEcologyMarketValueRecords> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(DaoEcologyMarketValueRecords::getId, id);
        wrapper.set(DaoEcologyMarketValueRecords::getStatus, status);
        return update(new DaoEcologyMarketValueRecords(),wrapper);
    }
}